﻿using IInject.Registration;

namespace IInject
{
	///<summary>
	/// Contains methods for injecting dependencies into an
	/// object that is not registered with the <see cref="Container"/>.
	///</summary>
	public static class ObjectBuilder
	{
		///<summary>
		/// Injects the <typeparamref name="T"/> with types located
		/// in the current <see cref="ContainerProvider.Current"/>.
		///</summary>
		///<typeparam name="T">The type to inject.</typeparam>
		///<returns>The initialized, injected <typeparamref name="T"/>.</returns>
		public static T Inject<T>()
		{
			var container = ContainerProvider.Current;
			var dependency = container.Resolver.Build(new RegistryContext
			{
				FromType = typeof(T),
				ToType = typeof(T),
				Scope = Scope.Singleton,
			});
			return container.Activator.Activate<T>(dependency);
		}
	}
}
